package com.tadpole.music.holder.me;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.me.VipListBean;
import com.tadpole.music.config.Constant;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.Mutils;
import com.tadpole.music.utils.NoDoubleClickListener;

import java.util.List;

/**
 * Created By 孙岩
 * on 2020/9/11
 */
public class MemberCenterViewHolder extends BaseViewHolder {
    private View itemView;
    private BaseAdapter.OnItemClickListener onItemClickListener;
    private BaseAdapter.OnChildClickListener onChildClickListener;

    private List<VipListBean.DataBean> list;
    private Activity activity;
    //图片
    private ImageView ivImage;
    //时间
    private TextView tvTime;
    //立即开通还是开始答题
    private TextView tvGo;
    public MemberCenterViewHolder(Activity activity,View itemView,BaseAdapter.OnChildClickListener onChildClickListener,BaseAdapter.OnItemClickListener onItemClickListener,List<VipListBean.DataBean> list) {
        super(itemView);
        this.itemView = itemView;
        this.onItemClickListener = onItemClickListener;
        this.onChildClickListener = onChildClickListener;
        this.activity = activity;
        this.list = list;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void init(final int position) {
        tvGo = itemView.findViewById(R.id.tvGo);
        ivImage = itemView.findViewById(R.id.ivImage);
        tvTime = itemView.findViewById(R.id.tvTime);

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.nomal_icon)
                .error(R.mipmap.nomal_icon)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(activity).load(Constant.IMAGE_HEAD+list.get(position).getApp_thumb()).apply(requestOptions).into(ivImage);

        if(list.get(position).isPaid()){
            tvTime.setText("会员到期时间："+list.get(position).getExpire_at());
            tvGo.setText("开始答题");

        }else{
            tvTime.setText("现在购买可使用到"+ Mutils.rowTime());
            tvGo.setText("立即开通");
        }

        itemView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onItemClickListener.onItemClick(itemView,position);
            }
        });

        tvGo.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onChildClickListener.onChildClick(tvGo,position);
            }
        });
    }
}
